<?php
// https://github.com/videlalvaro/php-amqplib
require_once __DIR__.'/vendor/autoload.php';
use PhpAmqpLib\Connection\AMQPStreamConnection;
use PhpAmqpLib\Message\AMQPMessage;

$connect = new AMQPStreamConnection('192.168.205.128', 5672, 'admin', '123456');
$channel = $connect->channel();
// 持久化队列，公有的，保留队列
$channel->queue_declare('task_queue', false, true, false, false);

$data = implode(' ', array_slice($argv, 1));
if (!$data) $data = 'Hello World';
// 消息持久化
$msg = new AMQPMessage($data, ['delivery_mode'=>AMQPMessage::DELIVERY_MODE_PERSISTENT]);
$channel->basic_publish($msg, '', 'task_queue');
echo " [x] Sent $data".PHP_EOL;

$channel->close();
$connect->close();